<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>ZDH etl jdbc任务新增</title>
    <meta name="keywords" content="ZDH etl jdbc任务新增">
    <meta name="description" content="ZDH etl jdbc任务新增">

    <link rel="shortcut icon" href="img/favicon.ico">

    <link href="css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="css/plugins/jsTree/style.min.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    <link href="css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link rel="stylesheet" data-name="vs/editor/editor.main" href="js/plugins/vs/editor/editor.main.css">
    <link rel="stylesheet" href="js/plugins/vs/editor/zdh.css">
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>ETL JDBC任务配置</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="buttons.html#">
                            <i class="fa fa-eye"></i>
                        </a>
                        <ul class="dropdown-menu dropdown-user">
                            <li><a href="javascript:void(0);" onclick="getResourceDesc()">功能说明</a>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="ibox-content">

                    <form id="etl_task_jdbc_add_form" name="etl_task_jdbc_add_form" method="post" class="form-horizontal"
                          action="">

                        <div class="form-group">
                            <label class="col-sm-2 control-label">归属产品</label>
                            <div class="col-sm-10">
                                <select id="product_code" name="product_code"
                                        data-placeholder="归属产品...."
                                        class="chosen-select form-control m-b" >
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">归属组</label>
                            <div class="col-sm-10">
                                <select id="dim_group" name="dim_group"
                                        data-placeholder="归属组...."
                                        class="chosen-select form-control m-b" >
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">ETL任务说明</label>
                            <div class="col-sm-10">
                                <input id="etl_context" name="etl_context" type="text"
                                       placeholder="ETL任务说明" class="form-control" aria-required="true"> </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">创建时间</label>
                            <div class="col-sm-10">
                                <input id="create_time" name="create_time" type="text" readonly
                                       placeholder="创建时间" class="form-control" aria-required="true"> </span>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <!-- 输入数据源开始-->

                        <div class="form-group">
                            <label class="col-sm-2 control-label">计算引擎</label>
                            <div class="col-sm-10">
                                <select id="engine_type" name="engine_type"
                                        data-placeholder="选择引擎..."
                                        class="chosen-select form-control m-b" tabindex="2">
                                    <option value="" mytype="">选择引擎...</option>
                                    <option value="spark" mytype="">SPARK</option>
                                    <option value="local" mytype="">本地</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">输入数据源选择</label>
                            <div class="col-sm-10">
                                <select id="data_sources_choose_input" name="data_sources_choose_input"
                                        data-placeholder="选择数据源..."
                                        class="chosen-select form-control m-b" tabindex="2">
                                    <option value="" mytype="">选择数据源...</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">数据源类型</label>
                            <div class="col-sm-10">
                                <input id="data_source_type_input" name="data_source_type_input" type="text" readonly
                                       placeholder="数据源类型" class="form-control" aria-required="true"> </span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">SQL逻辑</label>
                            <div class="col-sm-10">
                              <div id="etl_sql" name="etl_sql" class="monaco_div"></div>

                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">其他参数</label>
                            <div class="col-sm-10" id="div_data_sources_params">
                                <div id="data_sources_params_input" name="data_sources_params_input"
                                          class="monaco_div_100"></div>
                                <span class="help-block m-b-none"><a id="a_params" href="javascript:void(0);"
                                                                     onclick="resovle_params()">详细参数</a>; <a id="system_params" href="javascript:void(0);"
                                                                                                             onclick="system_params()">系统内置参数</a></span>
                            </div>

                        </div>

<!--                        <div class="hr-line-dashed"></div>-->


                        <!-- 输入数据源结束-->

                        <!-- 输出数据源开始-->

<!--                        <div class="form-group">
                            <label class="col-sm-2 control-label">输出数据源选择</label>
                            <div class="col-sm-10">
                                <select id="data_sources_choose_output" name="data_sources_choose_output"
                                        data-placeholder="选择数据源..."
                                        class="chosen-select form-control m-b" tabindex="2">
                                    <option value="" mytype="">选择数据源...</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">数据源类型</label>
                            <div class="col-sm-10">
                                <input id="data_source_type_output" name="data_source_type_output" type="text" readonly
                                       placeholder="数据源类型" class="form-control" aria-required="true"> </span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">常用参数</label>
                            <div class="col-sm-10">
                                <select id="file_type_output" name="file_type_output"
                                        data-placeholder="文件类型"
                                        class="chosen-select form-control m-b" tabindex="2" style="width: 30%">
                                    <option value="" mytype="">文件类型</option>
                                    <option value="csv" mytype="">CSV</option>
                                    <option value="csv" mytype="">TXT文本</option>
                                    <option value="orc" mytype="">ORC</option>
                                    <option value="parquet" mytype="">PARQUET</option>
                                    <option value="excel" mytype="">EXCEL</option>
                                    <option value="json" mytype="">JSON</option>
                                    <option value="xml" mytype="">XML</option>
                                    <option value="hudi" mytype="">HUDI</option>
                                    <option value="delta" mytype="">DELTA</option>
                                </select>
                                <select id="encoding_output" name="encoding_output"
                                        data-placeholder="编码"
                                        class="chosen-select form-control m-b" tabindex="2" style="width: 30%">
                                    <option value="" mytype="">编码</option>
                                    <option value="GBK" mytype="">GBK</option>
                                    <option value="GB2312" mytype="">GB2312</option>
                                    <option value="GB18030" mytype="">GB18030</option>
                                    <option value="UTF-8" mytype="">UTF-8</option>
                                    <option value="ISO-8859-1" mytype="">ISO-8859-1</option>
                                </select>
                                <select id="header_output" name="header_output"
                                        data-placeholder="标题"
                                        class="chosen-select form-control m-b" tabindex="2" style="width: 30%">
                                    <option value="" mytype="">标题</option>
                                    <option value="true" mytype="">有</option>
                                    <option value="false" mytype="">无</option>
                                </select>
                            </div>

                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">常用参数</label>
                            <div class="col-sm-10">
                                <select id="model_output" name="model_output"
                                        data-placeholder="写入模式"
                                        class="chosen-select form-control m-b" tabindex="2" style="width: 30%">
                                    <option value="" mytype="">写入模式</option>
                                    <option value="append" mytype="">追加</option>
                                    <option value="overwrite" mytype="">覆盖</option>
                                    <option value="errorifexists" mytype="">检查存在就报错</option>
                                    <option value="ignore" mytype="">检查存在忽略</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">分割符</label>
                            <div class="col-sm-10"><input id="sep_output" name="sep_output" type="text"
                                                          placeholder="分割符" class="form-control"></div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">分区字段</label>
                            <div class="col-sm-10"><input id="partition_by_output" name="partition_by_output" type="text"
                                                          placeholder="分区字段,example: etl_date" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">合并小文件个数</label>
                            <div class="col-sm-10"><input id="merge_output" name="merge_output" type="text" value="-1"
                                                          placeholder="合并小文件个数,默认-1,example: 1" class="form-control">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">其他参数</label>
                            <div class="col-sm-10" id="div_data_sources_params_output">
                                <textarea id="data_sources_params_output" name="data_sources_params_output"
                                          class="form-control" rows="2"
                                          placeholder="参数使用固定格式{&#34;k&#34;:&#34;v&#34;,&#34;k1&#34;:&#34;v1&#34;}"></textarea>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <div id="div_data_sources_table_name_output">
                                <label class="col-sm-2 control-label">输出表名</label>
                                <div class="col-sm-10">

                                    <select id="data_sources_table_name_output" name="data_sources_table_name_output"
                                            data-placeholder="选择数据表..."
                                            class="chosen-select form-control m-b" tabindex="2">
                                        <option value="">选择数据表...</option>
                                    </select>
                                </div>
                                </br>
                            </div>
                            <div class="form-group"></div>
                            <div id="div_data_sources_file_name_output">
                                <label class="col-sm-2 control-label">输出文件名</label>
                                <div class="col-sm-10">
                                    <input id="data_sources_file_name_output" name="data_sources_file_name_output"
                                           type="text"
                                           placeholder="表名/文件全路径" class="form-control" aria-required="true"
                                           onmouseleave="check_tb_name()"> </span>
                                </div>
                            </div>

                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">清空条件</label>
                            <div class="col-sm-10" id="div_data_sources_clear_output">
                                <textarea id="data_sources_clear_output" name="data_sources_clear_output"
                                          class="form-control" rows="2"
                                          placeholder="清空条件,使用sql语法 example: delete from user where etl_date=2019-12-01,如果是hbase数据源直接输入start_row_key,end_row_key 通过逗号分割 example: 001,100"></textarea>
                            </div>
                        </div>-->

                        <div class="hr-line-dashed"></div>
                        <!-- 元信息 业务相关-->

                        <div class="form-group">
                            <label class="col-sm-2 control-label">所属公司</label>
                            <div class="col-sm-10">
                                <input id="company" name="company"
                                       type="text"
                                       placeholder="填写公司" class="form-control" aria-required="true"> </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">所属部门</label>
                            <div class="col-sm-10">
                                <input id="section" name="section"
                                       type="text"
                                       placeholder="填写部门" class="form-control" aria-required="true"> </span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">所属业务</label>
                            <div class="col-sm-10">
                                <input id="service" name="service"
                                       type="text"
                                       placeholder="填写业务" class="form-control" aria-required="true"> </span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">更新说明</label>
                            <div class="col-sm-10">
                                <textarea id="update_context" name="update_context" class="form-control" rows="2"
                                          placeholder="更新说明"></textarea>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <!-- 输出数据源结束-->

                        <div class="form-group">
                            <div class="text-center">
                                <button id="save_etl_task" name="save_zdh" class="btn btn-primary"
                                        οnsubmit='return false'
                                        type="button">保存
                                </button>
                                <button id="update_etl_task" name="save_zdh" class="btn btn-primary"
                                        οnsubmit='return false'
                                        type="button">更新
                                </button>
                                <button id="reset" class="btn btn-white" type=reset>清空</button>
                            </div>
                        </div>


                    </form>

                </div>
            </div>


        </div>
    </div>
</div>


<div id="data_sources_params" class="ibox-content" style="display: none;">
    <p>数据源其他参数api</p>
    <ul>
        <li>JDBC:</li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;空</li>
        <li>HDFS:</li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sep:分割符,特殊字符需要转义,example:{"sep":"\\|"},{"sep","="}</li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fileType:文件类型,可选择parquet,orc,csv,json...,example {"fileType":"csv"}
        </li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; partitionBy:分区字段,example {"partitionBy":"ETL_DATE"}</li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; model:文件写入模式 默认append,overwrite,append,errorifexists,ignore,example
            {"model":"overwrite"}
        </li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; encoding:文件编码 默认UTF-8,example {"encoding":"gbk"}</li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; merge: 合并小文件 手动填写分区个数example {"merge":"50"}</li>
        <li>HIVE:</li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format:orc,parquet</li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;partitionBy:分区字段</li>
        <li>KAFKA:</li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msgType:消息类型,支持csv,json 2种格式</li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sep:分割符 当消息类型选择csv 时使用</li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;groupId:消费者组，默认g1</li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;kafka的topic 在文件名输入框配置</li>
        <li>HTTP:</li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;空</li>
        <li>REDIS:</li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data_type:写入数据类型，可选，string,hash,list,set,table</li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key.column:当选择写入数据类型为table 时配置此选项可以生成特定规则key</li>
        <li>CASSANDRA:</li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;空</li>
        <li>ES:</li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;空</li>
        <li>SFTP:</li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fileType:文件类型默认csv,可选csv,orc,parquet,json</li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sep:文件分割符,默认逗号分割</li>
        <li>KUDU:</li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;primary_key:指定表主键字段,默认会生成一个zdh_auto_md5字段作为主键</li>
        <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;replicas:指定副本个数,默认1个备份</li>
    </ul>
</div>

<script src="js/zdh_common.js"></script>
<script>
    var require = {
        paths: {
            'vs': 'js/plugins/vs'
        }
    };

</script>
<!-- 全局js -->
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>

<!-- Bootstrap table -->
<script src="js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<!-- 自定义js -->
<script src="js/content.js?v=1.0.0"></script>

<!-- Chosen -->
<script src="js/plugins/chosen/chosen.jquery.js"></script>

<!-- layer javascript -->
<script src="js/plugins/layer/layer.min.js"></script>


<script src="js/plugins/jsTree/jstree.min.js"></script>
<!-- iCheck -->
<script src="js/plugins/iCheck/icheck.min.js"></script>

<script src="js/plugins/vs/loader.js"></script>
<script src="js/plugins/vs/editor/editor.main.nls.js"></script>
<script src="js/plugins/vs/editor/editor.main.js"></script>
<script type="text/javascript" src="js/plugins/vs/basic-languages/sql/sql.js"></script>

<script src="js/admin/dim_product_common.js"></script>
<script src="js/admin/dim_group_common.js"></script>

<script>
    $(document).ready(function () {
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });
    });


    (function (document, window, $) {


        (function () {



            window.editor = monaco.editor.create(document.getElementById('etl_sql'), {
                value: '',
                language: 'sql',
                theme:'vs-dark'
            });

            window.editor_data_sources_params_input = monaco.editor.create(document.getElementById('data_sources_params_input'), {
                value: '',
                language: 'json',
                theme:'vs-dark'
            });

            var url = location.search; //这一条语句获取了包括问号开始到参数的最后，不包括前面的路径
            var params = url.substr(1);//去掉问号
            var pa = params.split("&");
            var s = new Object();//定义一个全局变量-存储任务ID
            for (var i = 0; i < pa.length; i++) {
                s[pa[i].split("=")[0]] = unescape(pa[i].split("=")[1]);
            }

            $('#engine_type').chosen();
            // $('#file_type_output').chosen();
            // $('#encoding_output').chosen();
            // $('#header_output').chosen();
            // $('#model_output').chosen();

            //定义特定数据源展示的div
            function fileShow() {
                console.info("fileShow");
                //表字段
                // $('#div_data_sources_table_name_output')[0].style.display = 'none';
                // $('#div_data_sources_file_name_output')[0].style.display = 'block';
            }

            //初始化数据源--把所有数据源都加载到下拉框
            function init_data_sources() {
                $.ajax({
                    type: 'POST',
                    url: server_context+"/data_sources_list",
                    dataType: 'json',
                    async: false,
                    data: '',
                    //成功返回
                    success: function (data) {
                        if(data.code != "200"){
                            layer.msg(data.msg);
                            return ;
                        }
                        var str_out = '<option value=\"\" mytype=\"\" hassubinfo=\"true\">空</option>';
                        var str_input = '<option value=\"\" mytype=\"\" hassubinfo=\"true\">空</option>';
                        for (var i = 0; i < data.result.length; i++) {
                            if(data.result[i].data_source_type == "JDBC"){
                                str_input += '<option value=\"' + data.result[i].id + "\" mytype=\"" + data.result[i].data_source_type + "\" hassubinfo=\"true\">" + data.result[i].data_source_context + "</option>";
                            }
                            str_out += '<option value=\"' + data.result[i].id + "\" mytype=\"" + data.result[i].data_source_type + "\" hassubinfo=\"true\">" + data.result[i].data_source_context + "</option>";
                        }

                        //输入数据源下拉框
                        $('#data_sources_choose_input').html(str_input);
                        $('#data_sources_choose_input').chosen().on("change", function (evt, params) {
                                $('#data_source_type_input').val($('#data_sources_choose_input').find("option:selected").attr("mytype"));
                        });
                        //输出数据源类型下拉框
                        // $('#data_sources_choose_output').html(str_out);
                        //
                        // $('#data_sources_choose_output').chosen().on("change", function (evt, params) {
                        //     // alert($('#data_sources_choose_input').val())
                        //     $('#data_source_type_output').val($('#data_sources_choose_output').find("option:selected").attr("mytype"));
                        //     $("#data_sources_choose_output").trigger("chosen:updated");
                        //     if ($('#data_sources_choose_output').find("option:selected").attr("mytype") == 'JDBC') {
                        //         init_table_name_output($('#data_sources_choose_output').val());
                        //
                        //         $('#div_data_sources_table_name_output')[0].style.display = 'block';
                        //         $('#div_data_sources_file_name_output')[0].style.display = 'block';
                        //     } else {
                        //         $('#div_data_sources_file_name_output')[0].style.display = 'block';
                        //         $('#div_data_sources_table_name_output')[0].style.display = 'none';
                        //
                        //     }
                        // });

                    },
                    //处理完成
                    complete: function () {
                        console.info("complete")
                    },
                    //报错
                    error: function (data) {
                        console.info("error: " + data.responseText);
                    }
                });
            }


            //根据数据源id 获取对应的tables
            function init_table_name_output(id) {

                var postData = {
                    id: id,
                };
                $.ajax({
                    type: 'POST',
                    url: server_context+"/etl_task_tables",
                    dataType: 'json',
                    data: postData,
                    //成功返回
                    success: function (data) {
                        if(data.code != "200"){
                            layer.msg(data.msg);
                            return ;
                        }
                        var str = '<option value=\"\" hassubinfo=\"true\"></option>';
                        for (var i = 0; i < data.length; i++) {
                            str += '<option value=\"' + data[i] + '\" hassubinfo=\"true\">' + data[i] + '</option>'
                        }
                        $('#data_sources_table_name_output').html(str);
                        $("#data_sources_table_name_output").trigger("chosen:updated");
                        $('#data_sources_table_name_output').chosen().on("change", function (evt, params) {
                            console.info("'data_sources_table_name_output' event change set text 'data_sources_file_name_output'");
                            $('#data_sources_file_name_output').val($('#data_sources_table_name_output').val())

                        });
                    },
                    //处理完成
                    complete: function () {
                        console.info("complete")
                    },
                    //报错
                    error: function (data) {
                        console.info("error: " + data.responseText);
                    }
                });


            }


            window.operateEvents = {
                'click #del': function (e, value, row, index) {
                    $('#exampleTableEvents').bootstrapTable('remove', {field: 'column_md5', values: [row.column_md5]});
                }
            };

            function operateFormatter(value, row, index) {
                return [
                    ' <button id="del" name="del" type="button" class="btn btn-outline btn-sm">\n' +
                    '                                        <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>\n' +
                    '                                    </button>'
                ].join('');
            }


            fileShow();
            //启动数据源select 初始化函数
            init_data_sources();
            //s.id=-1 表示新增,否则表示更新
            if (s.id == -1) {
                console.info("新增按钮触发");
                //$('#data_sources_table_name_input').chosen();
                //$('#data_sources_table_name_output').chosen();
                $('#update_etl_task').hide();
                $('#save_etl_task').show()
            } else {

                //init_table_name(s.id)

                if (s.is_copy == "true") {
                    console.info("拷贝按钮触发");
                    $('#update_etl_task').hide();
                    $('#save_etl_task').show();
                } else {
                    console.info("更新按钮触发");
                    $('#save_etl_task').hide();
                    $('#update_etl_task').show()
                }

                if (s.only_read == "true") {
                    $('#update_etl_task').hide();
                    $('#save_etl_task').hide();
                    $('#reset').hide();
                }
                buildParam()
            }

            function getMyDate(str) {
                var oDate = new Date(str),
                    oYear = oDate.getFullYear(),
                    oMonth = oDate.getMonth() + 1,
                    oDay = oDate.getDate(),
                    oHour = oDate.getHours(),
                    oMin = oDate.getMinutes(),
                    oSen = oDate.getSeconds(),
                    oTime = oYear + '-' + getzf(oMonth) + '-' + getzf(oDay) + " " + getzf(oHour) + ":" + getzf(oMin) + ":" + getzf(oSen);//最后拼接时间
                return oTime;
            };

            //补0操作
            function getzf(num) {
                if (parseInt(num) < 10) {
                    num = '0' + num;
                }
                return num;
            }


            function buildParam() {
                $('#enable_quality').prop("checked", false);
                if (s.id != '-1') {
                    console.info("更新按钮触发--开始赋值对应参数");
                    //开始赋值

                    $.ajax({
                        url: server_context+"/etl_task_jdbc_list",
                        data: "id=" + s.id,
                        type: "post",
                        async: false,
                        dataType: "json",
                        success: function (data) {
                            if(data.code != "200"){
                                layer.msg(data.msg);
                                return ;
                            }
                            console.info("success");
                            // layer.alert(JSON.stringify(data[0]))

                            var product_code=data.result[0].product_code;
                            $("#product_code").val(product_code);
                            $("#product_code").trigger("chosen:updated");

                            var dim_group=data.result[0].dim_group;
                            $("#dim_group").val(dim_group);
                            $("#dim_group").trigger("chosen:updated");

                            //获取输入数据源id
                            var data_sources_choose_input = data.result[0].data_sources_choose_input;
                            console.info("参数赋值:输入数据源id:" + data_sources_choose_input);


                            //获取ETL 说明
                            var etl_context = data.result[0].etl_context;
                            $("#etl_context").val(etl_context);

                            var create_time = data.result[0].create_time;
                            $("#create_time").val(getMyDate(create_time));


//                            //初始化输入数据源select 组件
                            $("#engine_type").val(data.result[0].engine_type);
                            $("#engine_type").trigger("chosen:updated");

                            $("#data_sources_choose_input").val(data_sources_choose_input);
                            $("#data_sources_choose_input").trigger("chosen:updated");

                            //获取输入数据源类型
                            var data_source_type_input = data.result[0].data_source_type_input;
                            $("#data_source_type_input").val(data_source_type_input);

                            var etl_sql = data.result[0].etl_sql;
                            //$("#etl_sql").val(etl_sql);
                            console.info(etl_sql);
                            window.editor.setValue(etl_sql);

                            //获取输出源数据其他参数
                            var data_sources_params_input = data.result[0].data_sources_params_input;
                            window.editor_data_sources_params_input.setValue(data_sources_params_input);


                            // 获取输出数据源
                            // var data_sources_choose_output = data[0].data_sources_choose_output;
                            // //初始化输入数据源select 组件
                            // $("#data_sources_choose_output").val(data_sources_choose_output);
                            // $("#data_sources_choose_output").trigger("chosen:updated");
                            //
                            // //获取输出数据源类型
                            // var data_source_type_output = data[0].data_source_type_output;
                            // $("#data_source_type_output").val(data_source_type_output);
                            //
                            // //输出文件类型参数
                            // var file_type_output = data[0].file_type_output;
                            // $("#file_type_output").val(file_type_output);
                            // $("#file_type_output").trigger("chosen:updated");
                            //
                            // var encoding_output = data[0].encoding_output;
                            // $("#encoding_output").val(encoding_output);
                            // $("#encoding_output").trigger("chosen:updated");
                            //
                            // var header_output = data[0].header_output;
                            // $("#header_output").val(header_output);
                            // $("#header_output").trigger("chosen:updated");
                            //
                            //
                            // var model_output = data[0].model_output;
                            // $("#model_output").val(model_output);
                            // $("#model_output").trigger("chosen:updated");
                            //
                            // var sep_output = data[0].sep_output;
                            // $("#sep_output").val(sep_output);
                            //
                            // var partition_by_output = data[0].partition_by_output;
                            // $("#partition_by_output").val(partition_by_output);
                            //
                            // var merge_output = data[0].merge_output;
                            // $("#merge_output").val(merge_output);
                            //
                            // //获取输出源数据其他参数
                            // var data_sources_params_output = data[0].data_sources_params_output;
                            // $("#data_sources_params_output").val(data_sources_params_output);
                            //
                            // //获取输出数据源表名
                            // var data_sources_table_name_output = data[0].data_sources_table_name_output;
                            // var data_sources_file_name_output = data[0].data_sources_file_name_output;

                            // if (data_source_type_output == "JDBC") {
                            //
                            //     $('#data_sources_file_name_output').val(data_sources_file_name_output);
                            //
                            //     //初始化数据源对应的表
                            //     var postData = {
                            //         id: data_sources_choose_output
                            //     }
                            //
                            //     $.ajax({
                            //         type: 'POST',
                            //         url: server_context+"/etl_task_tables",
                            //         dataType: 'json',
                            //         data: postData,
                            //         //成功返回
                            //         success: function (data_table) {
                            //
                            //             var str = '<option value=\"\" hassubinfo=\"true\"></option>';
                            //             for (var i = 0; i < data_table.length; i++) {
                            //                 str += '<option value=\"' + data_table[i] + '\" hassubinfo=\"true\">' + data_table[i] + '</option>'
                            //             }
                            //             $('#data_sources_table_name_output').html(str);
                            //             $("#data_sources_table_name_output").trigger("chosen:updated");
                            //             $('#data_sources_table_name_output').chosen();
                            //
                            //             //表名再数据源中匹配不到,说明是自己添加的
                            //             if (str.search(data_sources_table_name_output) == -1) {
                            //                 check_tb_name()
                            //             }
                            //             $('#data_sources_table_name_output').val(data_sources_table_name_output);
                            //             $("#data_sources_table_name_output").trigger("chosen:updated");
                            //         },
                            //         //处理完成
                            //         complete: function () {
                            //             console.info("complete")
                            //         },
                            //         //报错
                            //         error: function (data_table) {
                            //             console.info("error: " + data_table.responseText);
                            //         }
                            //     });
                            //
                            //     $('#div_data_sources_table_name_output')[0].style.display = 'block';
                            //     $('#div_data_sources_file_name_output')[0].style.display = 'block';
                            //
                            // } else {
                            //
                            //     $('#data_sources_file_name_output').val(data_sources_file_name_output);
                            //     $('#div_data_sources_table_name_output')[0].style.display = 'none';
                            //     $('#div_data_sources_file_name_output')[0].style.display = 'block';
                            // }
                            //
                            // //获取输出删除条件
                            // var data_sources_clear_output = data[0].data_sources_clear_output;
                            // $('#data_sources_clear_output').val(data_sources_clear_output);

                            //获取元数据信息
                            var company = data.result[0].company;
                            $('#company').val(company);

                            var section = data.result[0].section;
                            $('#section').val(section);

                            var service = data.result[0].service;
                            $('#service').val(service);

                            var update_context = data.result[0].update_context;
                            $('#update_context').val(update_context)

                        },
                        error: function (data) {
                            console.info("error: " + data.responseText);
                        }

                    });


                }
            }

        })();

    })(document, window, jQuery);

    //初始化a 标签 弹出具体参数解析功能
    function resovle_params() {

        layer.open({
            type: 1,
            shade: false,
            title: false, //不显示标题
            area: ["30%", "40%"],
            content: $('#data_sources_params'), //捕获的元素
            cancel: function (index) {
                layer.close(index);
                //this.content.show();
                //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构',{time: 5000});
            }
        });
    }


    function check_tb_name() {
        if ($('#data_source_type_output').val() == "JDBC") {

            if ($("#data_sources_table_name_output").html().search('<option value=\"' + $('#data_sources_file_name_output').val() + '\" hassubinfo="true">') == -1) {
                var op = '<option value=\"' + $('#data_sources_file_name_output').val() + '\" hassubinfo="true">' + $('#data_sources_file_name_output').val() + '</option>'

                $("#data_sources_table_name_output").html($("#data_sources_table_name_output").html() + op)
                $("#data_sources_table_name_output").trigger("chosen:updated");
                $("#data_sources_table_name_output").chosen();
                $("#data_sources_table_name_output").val($('#data_sources_file_name_output').val())
                $("#data_sources_table_name_output").trigger("chosen:updated");
            }
        }
    }

    function getFileName(o) {
        var pos = o.lastIndexOf("\\");
        return o.substring(pos + 1);
    }

    $('#save_etl_task').click(function () {

        if ($('#etl_context').val() == '') {
            layer.msg("ETL任务说明不能为空！");
            return;
        }

        var formData = new FormData(document.getElementById("etl_task_jdbc_add_form"));
        formData.set("etl_sql",window.editor.getValue());
        formData.set("data_sources_params_input",window.editor_data_sources_params_input.getValue());
        $.ajax({
            type: 'POST',
            url: server_context+"/etl_task_jdbc_add",
            async: false,
            processData: false,
            contentType: false,
            dataType: 'json',
            data: formData,
            //发送数据前
            beforeSend: function () {
                // 禁用按钮防止重复提交
                $("#save_etl_task").attr({disabled: "disabled"});
            },
            //成功返回
            success: function (data) {
                $("#save_etl_task").removeAttr('disabled');
                if(data.code != '200'){
                    console.error(data.msg);
                    layer.msg("执行失败");
                    return ;
                }
                layer.msg("执行成功");


                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            },
            //处理完成
            complete: function () {
                console.info("complete")
            },
            //报错
            error: function (data) {
                $("#save_etl_task").removeAttr('disabled');
                console.info("error: " + data.responseText);
            }
        });

    });


    $('#update_etl_task').click(function () {

        if ($('#etl_context').val() == '') {
            layer.msg("ETL任务说明不能为空！");
            return;
        }

        var url = location.search; //这一条语句获取了包括问号开始到参数的最后，不包括前面的路径
        var params = url.substr(1);//去掉问号
        var pa = params.split("&");
        var s = new Object();
        for (var i = 0; i < pa.length; i++) {
            s[pa[i].split("=")[0]] = unescape(pa[i].split("=")[1]);
        }

        var formData = new FormData(document.getElementById("etl_task_jdbc_add_form"));
        formData.set("etl_sql",window.editor.getValue());
        formData.set("id",s.id);
        formData.set("data_sources_params_input",window.editor_data_sources_params_input.getValue());
        $.ajax({
            type: 'POST',
            url: server_context+"/etl_task_jdbc_update",
            processData: false,
            contentType: false,
            dataType: 'json',
            data: formData,
            //发送数据前
            beforeSend: function () {
                // 禁用按钮防止重复提交
                $("#update_etl_task").attr({disabled: "disabled"});
            },
            //成功返回
            success: function (data) {
                $("#update_etl_task").removeAttr('disabled');
                if(data.code != "200"){
                    console.error(data.msg);
                    layer.msg("执行失败");
                    return ;
                }
                layer.msg("执行成功");

                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            },
            //处理完成
            complete: function () {
                console.info("complete")
            },
            //报错
            error: function (data) {
                $("#update_etl_task").removeAttr('disabled');
                console.info("error: " + data.responseText);
            }
        });

    })

</script>

</body>

</html>
